﻿using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NeonLampTest.Common
{
    public abstract class SurroundNodeBase
    {
        public Color DefaultColor { get; private set; }
        public Color StartColor { get; set; }
        public Color EndColor { get; set; }
        public int X { get; set; }
        public int Y { get; set; }
        public int Step { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        public int SurroundWidth { get; set; }
        public int Displacement { get; protected set; } = 1;
        public virtual bool IsNext => Displacement >= Width;
        public SurroundNodeBase Next { get; set; }
        public int ColorStep => (int)Math.Ceiling(255f / (this.Width / (float)Step));
        public void SetDefaultColor(Color color)
        {
            DefaultColor = color;
            StartColor = EndColor = DefaultColor;
        }
        public void ChangeStartColor()
        {
            Color startColor = StartColor;
            ChangeColor(ColorStep << 1, ref startColor);
            StartColor = startColor;
        }
        public void ChangeEndColor()
        {
            Color endColor = EndColor;
            ChangeColor(ColorStep,ref endColor);
            EndColor = endColor;
        }
        protected void ChangeColor(int step,ref Color color)
        {
            int alpha = color.A - step;
            if (alpha < 0)
                alpha = 0;
            color = Color.FromArgb(alpha, color.R, color.G, color.B);
        }
        public virtual void Default()
        {
            Displacement = 1;
            X = 0;
            Y = 0;
            StartColor = EndColor = DefaultColor;
        }
        public void SizeChange(int width, int height)
        {
            this.Width = width;
            this.Height = height;
            Default();
        }
        public abstract void Change();
        public abstract void Draw(Graphics g);

    }
}
